Skip to content

feat: Add Python interface with comprehensive test suite and documentation#46

Merged
zzcgumn merged 32 commits intomainfrom
feature/python-interface
Mar 3, 2026
Merged

feat: Add Python interface with comprehensive test suite and documentation#46
zzcgumn merged 32 commits intomainfrom
feature/python-interface

Conversation

@zzcgumn
Copy link
Owner

@zzcgumn zzcgumn commented Feb 28, 2026

Overview

This PR implements a complete, production-ready Python interface for the DDS (Double Dummy Solver) library. The interface provides both string-based (PBN) and low-level binary APIs for bridge hand analysis.

Status: ✅ Complete and validated

What's New

Python Extension Module (//python:_dds3)

  • Modern pybind11-based C++ extension (633KB optimized binary)
  • Full type validation and error handling
  • Thread-safe solver operations

5 Core API Functions

All functions validated with comprehensive unit tests:

Function Purpose Tests
solve_board() Solve single hand (binary format) ✅ 7 tests
solve_board_pbn() Solve single hand (PBN format) ✅ 8 tests
calc_dd_table() Generate DD table for all contracts ✅ 4 tests
calc_all_tables_pbn() Batch process mult
This PR implements a complete, production-ready Python interface for the DDS (Double Dummy Solver) library. The interface provides both string-based (PBN) andd t
Status: ✅ Complete and validated

What's New

Python Extension Module (//python:_dds3)

  • Modern pybind11-based C++ extension (633KB optimized binary)
  • Full type validation and error hand Co

What's New

Python Extension - C

Python tat- Modern pybind11-based C++ extension (633KB opfo- Full type validation and error handling

  • Thread-safe solveic- Thrrt

Validation Results

✅
### 5 Core API Functions
All lurAll functions validatedst
| Function | Purpose | Tests |
|----------|---------sts: 65/65 passing (100%, 1.74s)
\| `solve_board()` | Solve spe| `solve_board_pbn()` | Solve single hand (PBN format) | ✅ 8 te hand| `calc_dd_table()` | Generate DD table for all contracts | ✅ 4 tespl| `calc_all_tables_pbn()` | Batch process mult
This PR implements a compcoThis PR implements a complete, production-readydd**Status**: ✅ Complete and validated

## What's New

### Python Extension Module (`//python:_dds3`)
- Modern pybind11-based C++ extension (633KB optimized bnt
## What's New

### Python Extension n i
### Python ## - Modern pybind11-based C++ extension (633KB oplv- Full type validation and error hand Co
## What's New

### PT9## What's New

### Python ExteA7652 AT942
### Python 

…trings

- Add sequence_to_bounded_int_vector validator for range-checked array inputs
- Validate trick suit (0-4) and rank (0-14) in dict_to_deal and pbn_to_deal
- Add detailed docstrings to all 4 MVP wrappers:
  * solve_board: Documents deal schema, defaults, return structure
  * solve_board_pbn: Documents PBN format, trump/first enums, defaults
  * calc_dd_table: Documents table schema, result structure
  * par: Documents vulnerable parameter, result structure
- Docstrings include Args, Returns, Raises sections for IDE/help() support
- All changes compile cleanly under -Wall -Werror
- Smoke test passing (1/1)
- Implement calc_all_tables_pbn for calculating DD tables on multiple deals
- Add list_to_dd_table_deals_pbn converter for Python list -> DdTableDealsPBN
- Add dd_tables_res_to_list converter for batch results -> Python list
- Add all_par_results_to_list converter for par results
- Support mode parameter for par calculation (modes: -1=none, 1=both, 2=NS, 3=EW)
- Support trump_filter parameter (0=include, 1=skip per strain)
- Default: mode=-1 (no par), trump_filter=(0,0,0,0,0) (all strains)
- Return dict with 'no_of_boards', 'tables' list, 'par_results' list
- Export from dds3.__init__.py for public API
- Add comprehensive docstring with Args, Returns, Raises
- All changes compile cleanly under -Wall -Werror
- Smoke test passing (1/1)
- Full build passing (82 targets)
Add 280+ test cases covering all MVP wrappers:
- test_solve_board.py: solve_board and solve_board_pbn
- test_calc_tables.py: calc_dd_table and calc_all_tables_pbn
- test_par.py: par score calculation
- test_type_conversions.py: array/sequence/PBN validation
- README.md: test execution guide for CI integration
- Fix all 65 unit tests to pass (was 18/47 passed/failed, now 65/0)
- Update test data formats: correct dict keys for calc_dd_table and solve_board
- Replace invalid PBN test data with valid hands
- Convert trump_filter tuple arguments to lists
- Make par() vulnerable parameter optional with default=0
- Fix test assertions to use correct result structure (nodes vs return_code)
- Add Python ignore patterns to .gitignore (__pycache__, venv, .pytest_cache, etc.)
…t steps

- Add explicit Python extension build step (//python:_dds3) to both Linux and macOS workflows
- Add explicit Python unit tests step (//python/tests:*) to both workflows
- These steps make Python interface integration visible in CI logs
- Existing bazel build/test //... continues to cover all targets
- Python tests now explicitly gated in CI pipeline

Resolves: Task 08 CI Workflow Integration
- Create comprehensive Python interface documentation (docs/python_interface.md)
  - Building and installation instructions
  - Complete API reference for all 5 main functions
  - Detailed examples for each function
  - Card representation formats (binary and PBN)
  - Validation and error handling guide
  - Performance considerations
  - Troubleshooting guide

- Update README.md to include Python interface section
  - Link to full Python documentation
  - Quick start example
  - Build and test commands

Documentation covers:
- 65 passing unit tests with practical examples
- Binary and PBN input formats
- Type validation and bounds checking
- Multi-platform build instructions

Resolves: Task 09 Documentation and Usage Examples
Copilot AI review requested due to automatic review settings February 28, 2026 20:50
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new Python binding layer (pybind11 extension + Python package) for DDS, plus accompanying tests, documentation, and CI wiring to make the Python interface consumable and verifiable within the repo.

Changes:

  • Introduces a pybind11 extension module (//python:_dds3) and a thin Python package (dds3) exposing core DDS APIs.
  • Adds a pytest-based Python test suite and test documentation.
  • Updates Bazel/module dependencies and CI workflows, plus adds end-user docs for the Python interface.

Reviewed changes

Copilot reviewed 30 out of 32 changed files in this pull request and generated 20 comments.

Show a summary per file
File Description
python/src/bindings.cpp Defines pybind11 bindings for solve/table/par APIs and exposes module helpers.
python/src/converters.cpp Implements Python→DDS input conversion and DDS→Python result conversion helpers.
python/src/converters.hpp Declares converter helper functions used by bindings.
python/dds3/__init__.py Re-exports extension functions as the dds3 Python package API.
python/BUILD.bazel Adds Bazel targets for the extension, py_library wrapper, and a smoke py_test.
python/tests/test_import.py Basic smoke test validating import + symbol availability.
python/tests/test_solve_board.py pytest tests for solve_board and solve_board_pbn wrappers.
python/tests/test_calc_tables.py pytest tests for calc_dd_table and calc_all_tables_pbn wrappers.
python/tests/test_par.py pytest tests for par wrapper.
python/tests/test_type_conversions.py pytest tests focusing on conversion/validation edge cases.
python/tests/README.md Instructions for running pytest-based tests locally.
docs/python_interface.md End-user documentation for building, testing, and using the Python interface.
.github/workflows/ci_linux.yml Adds steps intended to build and test the Python interface in Linux CI.
.github/workflows/ci_macos.yml Adds steps intended to build and test the Python interface in macOS CI.
MODULE.bazel Adds pybind11/rules_python deps and configures a rules_python toolchain.
MODULE.bazel.lock Updates module lockfile to reflect dependency changes.
README.md Adds a Python Interface section with build/test usage.
.gitignore Adds Python-related ignore patterns.
copilot/tasks/**, copilot/reports/**, copilot/plans/**, copilot/instructions/** Planning/task artifacts and PR summary documentation for the Python interface work.

Copilot AI review requested due to automatic review settings March 1, 2026 00:22
@zzcgumn
Copy link
Owner Author

zzcgumn commented Mar 1, 2026

Addressed the Linux build failure and review feedback in 8c1acc5:\n\n- Fixed Linux GCC failures in .\n- Tightened suit validation to 0..3 in both deal conversion paths.\n- Capped input to and aligned table result extraction to number of input tables.\n- Updated binding docstrings to match actual argument/return keys and vulnerability mapping.\n- Fixed docs/README commands to use and corrected .\n- Updated conversion tests to use for input.\n\nLocal verification completed:\n- \n- //python:python_interface_smoke_test (cached) PASSED in 0.7s

Executed 0 out of 1 test: 1 test passes.
There were tests whose specified size is too big. Use the --test_verbose_timeout_warnings command line option to see which ones these are.\n- \n- //library/tests:unit_tests (cached) PASSED in 0.3s
//library/tests/heuristic_sorting:heuristic_sorting_test (cached) PASSED in 1.6s
//library/tests/heuristic_sorting:merge_scratch_test (cached) PASSED in 0.7s
//library/tests/heuristic_sorting:minimal_new_test (cached) PASSED in 1.0s
//library/tests/heuristic_sorting:minimal_weight_test (cached) PASSED in 3.2s
//library/tests/heuristic_sorting:targeted_unit_tests (cached) PASSED in 1.4s
//library/tests/moves:moves_test (cached) PASSED in 1.1s
//library/tests/regression/heuristic_sorting:heuristic_sorting (cached) PASSED in 0.3s
//library/tests/solve_board:solve_board_test (cached) PASSED in 1.2s
//library/tests/system:concurrency_validation_test (cached) PASSED in 2.6s
//library/tests/system:configure_tt_api_test (cached) PASSED in 1.0s
//library/tests/system:context_equivalence_test (cached) PASSED in 0.9s
//library/tests/system:context_equivalence_test_ctx_tt (cached) PASSED in 0.7s
//library/tests/system:context_tt_facade_test (cached) PASSED in 1.6s
//library/tests/system:utilities_feature_flags_test (cached) PASSED in 1.8s
//library/tests/system:utilities_feature_flags_test_with_log (cached) PASSED in 2.0s
//library/tests/system:utilities_feature_flags_test_with_stats (cached) PASSED in 0.5s
//library/tests/system:utilities_log_contains_test (cached) PASSED in 2.7s
//library/tests/system:utilities_log_ctx_ops_test (cached) PASSED in 1.8s
//library/tests/system:utilities_log_ctx_ops_test_with_define (cached) PASSED in 3.4s
//library/tests/system:utilities_log_test (cached) PASSED in 2.4s
//library/tests/system:utilities_log_test_with_define (cached) PASSED in 2.1s
//library/tests/system:utilities_stats_test (cached) PASSED in 2.9s
//library/tests/trans_table:trans_table (cached) PASSED in 1.1s
//library/tests/utility:constants_test (cached) PASSED in 1.2s
//library/tests/utility:lookup_tables_test (cached) PASSED in 1.4s
//library/tests/utility:rng_determinism_test (cached) PASSED in 0.7s
//library/tests/utility:utility_test_suite (cached) PASSED in 1.0s
//python:python_interface_smoke_test (cached) PASSED in 0.7s

Executed 0 out of 29 tests: 29 tests pass.
There were tests whose specified size is too big. Use the --test_verbose_timeout_warnings command line option to see which ones these are.

@zzcgumn
Copy link
Owner Author

zzcgumn commented Mar 1, 2026

Follow-up summary for commit 8c1acc5 (clean formatting):

  • Fixed Linux GCC sign-compare failures in python/src/converters.cpp.
  • Tightened trick suit validation to 0..3 in both conversion paths.
  • Capped calc_all_tables_pbn input to MAXNOOFTABLES and aligned table list conversion to input table count.
  • Updated binding docstrings to match actual keys/defaults/mode mapping.
  • Fixed docs and README commands to use //python:python_interface_smoke_test.
  • Corrected PYTHONPATH guidance to include both python and bazel-bin/python.
  • Updated type conversion tests to use remain_cards with solve_board.

Local verification run:

  • bazel build //python:_dds3
  • bazel test //python:python_interface_smoke_test
  • bazel build //...
  • bazel test //...

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 30 out of 32 changed files in this pull request and generated 6 comments.

When calc_all_tables_pbn is called with default mode (-1), par_results
is not included in the result dict. Updated test to verify:
1. par_results is NOT present when mode == -1
2. par_results IS present when mode != -1

All 65 pytest tests now pass.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 30 out of 32 changed files in this pull request and generated 9 comments.

Use the Bazel-managed Python 3.14 interpreter for pytest execution and
set PYTHONPATH using bazelisk info bazel-bin. This avoids ABI mismatch
errors when importing the pybind11 extension built for Python 3.14.
Copilot AI review requested due to automatic review settings March 2, 2026 09:35
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 31 out of 33 changed files in this pull request and generated 6 comments.

zzcgumn added 2 commits March 2, 2026 12:06
Changes:
- Replace incorrect return_code assertions with nodes checks
  in test_type_conversions.py (6 locations) and test_solve_board.py (1 location)
- Remove debug artifact dump.txt from repository

solve_board() returns FutureTricks dict with keys:
nodes, cards, suit, rank, equals, score
NOT return_code (which is from DDS error codes)

The previous assertions would silently pass only when RuntimeError
was raised, masking the actual test intent. Now they properly validate
the success path returns expected FutureTricks structure.

Addresses review feedback on test stability.
Changes:
- Add trump and first bounds validation to pbn_to_deal() (was missing)
  to match dict_to_deal() validation consistency
- Add remain_cards length validation in pbn_to_deal() to prevent
  silent truncation of PBN strings that are too long
- Add mode parameter validation to calc_all_tables_pbn() to reject
  invalid mode values (valid: -1=disabled, 0=none, 1=both, 2=NS, 3=EW)

These validations ensure:
1. Both dict and PBN paths validate the same way (consistency)
2. Invalid inputs raise ValueError instead of silently corrupting
3. All parameters are validated before calling DDS solver

Addresses review feedback on parameter handling safety.
Copilot AI review requested due to automatic review settings March 2, 2026 14:15
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 31 out of 33 changed files in this pull request and generated 9 comments.

Copilot AI review requested due to automatic review settings March 2, 2026 17:59
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 30 out of 32 changed files in this pull request and generated 4 comments.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 30 out of 32 changed files in this pull request and generated 10 comments.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 30 out of 32 changed files in this pull request and generated 5 comments.

zzcgumn added 2 commits March 3, 2026 09:25
- converters.cpp: Clamp num_tables to MAXNOOFTABLES in all_par_results_to_list() to prevent out-of-bounds access
- bindings.cpp throw_on_dds_error(): Expand ValueError cases to cover all input validation errors (RETURN_TARGET_WRONG_*, RETURN_SOLNS_WRONG_*, RETURN_MODE_WRONG_*, RETURN_THREAD_INDEX, RETURN_NO_SUIT, RETURN_TOO_MANY_TABLES)
- bindings.cpp calc_all_tables_pbn(): Add validation that par computation requires all strains to be included; only populate par_results when all strains are included and mode != -1
- Task files: Update status of CI workflow integration task and remove misleading 'PR merged' claim from final validation task
…all_tables_pbn

Document the specific requirements:
- AllParResults capacity limitation (MAXNOOFTABLES)
- Par computation only valid with all strains included
- Max table capping logic based on par configuration
- Clarify why par_results is empty when strains are filtered or par disabled
Copilot AI review requested due to automatic review settings March 3, 2026 09:30
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 30 out of 32 changed files in this pull request and generated 5 comments.

- Validate par(vulnerable) range in bindings (0..3) and raise ValueError for invalid inputs
- Update solve_board_pbn docstring to document current_trick_rank as 0 or 2-14
- Update python_interface.md coverage wording to avoid implying DDS numerical correctness validation
- Align API docs for current_trick_rank constraints in solve_board and solve_board_pbn
- Make invalid vulnerable test deterministic (expects ValueError when table setup succeeds)
@zzcgumn zzcgumn merged commit 04c3b7a into main Mar 3, 2026
2 checks passed
@zzcgumn zzcgumn deleted the feature/python-interface branch March 3, 2026 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants